using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Design;

namespace Blimpbots.Recognition
{
    public partial class FilmFrame : UserControl
    {
        private Image sceneThumb;
        private bool isSelected;

        public bool IsSelected
        {
            get { return isSelected; }
            set { isSelected = value; Invalidate(); }
        }
       
        [Description("Scene to show a thumbnail of."), Category("Appearance")]
        public Image Scene {
            set { MakeThumb(value);  Invalidate(); } 
            get { return sceneThumb; } 
        }

        private void MakeThumb(Image scene)
        {
            sceneThumb = new Bitmap(this.Width, this.Height);
            using (Graphics g = Graphics.FromImage(sceneThumb))
            {
                // Make a good thumbnail
                g.InterpolationMode 
                    = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                g.DrawImage(scene, 0, 0, sceneThumb.Width, sceneThumb.Height);
            }
        }

        public FilmFrame()
        {
            InitializeComponent();
            this.SetStyle( ControlStyles.AllPaintingInWmPaint | 
                            ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
        }

        private void FilmFrame_Paint(object sender, PaintEventArgs e)
        {
            if(sceneThumb != null)
                e.Graphics.DrawImage(sceneThumb, e.ClipRectangle, e.ClipRectangle, GraphicsUnit.Pixel);

            if (isSelected)
            {
                Pen p = new Pen(Color.Chartreuse, 4.0F);
                e.Graphics.DrawRectangle(p, 2, 2, this.Width - 4, this.Height - 4);
            }
        }

    }
}
